package com.game.HUD;

import javax.microedition.khronos.opengles.GL10;

import com.game.R;

import object.obj2D.graphics.TexSquare;
import object.obj2D.graphics.Texture;
import system.Device;
import system.Graphics;

public class ShowEnemyHP extends ShowGUIItem {
	
	static private int m_iTexEnemyBloodBackgroundID;
	static private int m_iTexEnemyBloodID;
	static private int m_iEnemyBloodBgWidth = 160;
	static private int m_iEnemyBloodBgHeight = 21;
	static private int m_iEnemyBloodWidth = 145;
	static private int m_iEnemyBloodHeight = 20;
	static private TexSquare m_texEnemyBloodSquare;
	static private TexSquare m_texEnemyBloodBgSquare;
	static private int MAX_HP_ENEMY = 1000;
	static private int m_iEnemyHP = 1000;
	private static short ENEMY_BLOOD_OFFSET = 12;
	static private Texture m_texture;
	private static GL10 gl;
	private static int m_fSrcWidth;
	private static int m_fSrcHeight;
	
	public static void Init()
	{
		m_fSrcWidth = Device.GetWidth();
		m_fSrcHeight = Device.GetHeight();
		gl = Graphics.GetGraphics();
		m_texture = new Texture();
		
		m_iTexEnemyBloodID = m_texture.initTexture(R.drawable.blood_enemy);
		m_iTexEnemyBloodBackgroundID = m_texture.initTexture(R.drawable.blood_bg_enemy);
		
		Device.DisableScaleFactor();
		m_texEnemyBloodSquare = new TexSquare(m_iEnemyBloodWidth, m_iEnemyBloodHeight);
		m_texEnemyBloodBgSquare = new TexSquare(m_iEnemyBloodBgWidth, m_iEnemyBloodBgHeight);
		Device.EnableScaleFactor();
		
		
	}
	
	public static  void Update(){
		MAX_HP_ENEMY = s_level.GetTotalEnemyHP();
		m_iEnemyHP = s_level.GetTotalAliveEnemyHP();
	}
	
	public static void Render(){
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glPushMatrix();
		// EnemyBlood background
		gl.glLoadIdentity();
		gl.glTranslatef((m_fSrcWidth - m_iEnemyBloodBgWidth)/2, (m_fSrcHeight - m_iEnemyBloodBgHeight)/2 - 4, 0);
		m_texture.loadTexture(m_iTexEnemyBloodBackgroundID);
		m_texEnemyBloodBgSquare.Render();
		
		
		// EnemyBlood
		float x = ((float) m_iEnemyHP / MAX_HP_ENEMY);
		float EnemyBloodWidth = (int)(x*m_iEnemyBloodWidth);
		
		gl.glLoadIdentity();
		gl.glTranslatef((m_fSrcWidth - EnemyBloodWidth)/2 - ENEMY_BLOOD_OFFSET, (m_fSrcHeight - m_iEnemyBloodHeight)/2 - 4, 0);
		
		m_texEnemyBloodSquare.SetTexCoord(new float[]{
			0.0f, 0.0f,
			x, 0.0f,
			x, 1.0f,
			0.0f, 1.0f
		});
		m_texEnemyBloodSquare.SetWidth(EnemyBloodWidth);
		m_texture.loadTexture(m_iTexEnemyBloodID);
		m_texEnemyBloodSquare.Render();
		
		gl.glPopMatrix();
	}
}
